<?php
session_start();
if (!isset($_SESSION["admin_id"])) {
    header("Location: admin.php");
    exit;
}

if (!isset($_GET["id"])) {
    die("Geçersiz istek.");
}

$ogrenci_id = $_GET["id"];

try {
    $db = new PDO("mysql:host=localhost;dbname=yenicesi_2305610353;charset=utf8", "yenicesi_2305610353", "2305610353C.");
} catch (PDOException $e) {
    die("Veritabanı bağlantı hatası: " . $e->getMessage());
}

$sorgu = $db->prepare("SELECT * FROM ogrenciler WHERE id = ?");
$sorgu->execute([$ogrenci_id]);
$ogrenci = $sorgu->fetch();

if (!$ogrenci) {
    die("Öğrenci bulunamadı.");
}
?>

<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <title>Öğrenci Düzenle</title>
    <link rel="stylesheet" href="css/admin_dashboard.css">
</head>
<body>

<header>🎓 Öğrenci Bilgilerini Güncelle</header>

<div class="container">
    <form action="ogrenci_guncelle.php" method="POST">
        <input type="hidden" name="id" value="<?= $ogrenci["id"] ?>">

        <label>Ad Soyad:</label>
        <input type="text" name="ad" value="<?= htmlspecialchars($ogrenci["ad"]) ?>" required><br><br>

        <label>Email:</label>
        <input type="email" name="email" value="<?= htmlspecialchars($ogrenci["email"]) ?>" required><br><br>

        <label>Öğrenci No:</label>
        <input type="text" name="ogrenci_no" value="<?= htmlspecialchars($ogrenci["ogrenci_no"]) ?>" required><br><br>

        <label>Durum:</label>
        <select name="durum">
            <option value="Aktif" <?= $ogrenci["durum"] == "Aktif" ? "selected" : "" ?>>Aktif</option>
            <option value="Pasif" <?= $ogrenci["durum"] == "Pasif" ? "selected" : "" ?>>Pasif</option>
        </select><br><br>

        <button type="submit">Kaydet</button>
        <a href="admin_dashboard.php" class="back-link">⬅ Geri Dön</a>
    </form>
</div>

</body>
</html>
